/*
 * FramePreguntaAfectivoAyuda.java
 *
 * Created on 28 de mayo de 2009, 0:59
 */

package GUI;

;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import jess.*;
/**
 *
 * @author  David
 */
public class FramePreguntaAfectivoAyuda extends javax.swing.JFrame {
    
    private JFrame framePadre;
    private Vector vector;
    BufferedWriter writer;
    BufferedReader reader;
    Rete engine;
    Batch batch;

    /** Creates new form FramePreguntaAfectivoAyuda */
    public FramePreguntaAfectivoAyuda(JFrame fr) {
        engine = new Rete ();
    	batch = new Batch();
        this.setVisible(true);
        this.framePadre=fr;
        initComponents();
    }


    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelAyuda = new javax.swing.JLabel();
        jLabel_que_Ayudamos = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel_NivelDeEstudios = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabelSeguirEstudiando = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jComboBox5 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBox6 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBox7 = new javax.swing.JComboBox();
        jComboBox8 = new javax.swing.JComboBox();
        jComboBox9 = new javax.swing.JComboBox();
        jButtonAsesorar = new javax.swing.JButton();
        jButtonVolver = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelAyuda.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabelAyuda.setText("Ayuda General");

        jLabel_que_Ayudamos.setText("¿En qué podemos ayudarle?");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Trabajo", "Personalidad", "Visión de la vida", "Condición física", "Académicamente" }));

        jLabel_NivelDeEstudios.setText("Nivel de estudios");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Graduado", "Eso", "Bachiller", "Universitario" }));

        jLabelSeguirEstudiando.setText("¿Quiere seguir estudiando?");

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jLabel1.setText("¿Tiene curriculum?");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jLabel2.setText("¿Piensa?");

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jLabel3.setText("¿Tiene metas?");

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jLabel4.setText("¿Es feliz?");

        jLabel5.setText("Peso");

        jLabel6.setText("¿Hace dieta?");

        jComboBox7.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jComboBox8.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jComboBox9.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Si", "No" }));

        jButtonAsesorar.setText("Asesorar");
        jButtonAsesorar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAsesorarActionPerformed(evt);
            }
        });

        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(152, Short.MAX_VALUE)
                .addComponent(jLabelAyuda)
                .addGap(332, 332, 332))
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabelSeguirEstudiando, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, 0, 208, Short.MAX_VALUE)
                    .addComponent(jLabel_que_Ayudamos, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel_NivelDeEstudios, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(73, 73, 73)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(39, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(196, 196, 196)
                .addComponent(jButtonVolver)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addComponent(jButtonAsesorar)
                .addGap(210, 210, 210))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLabelAyuda)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_que_Ayudamos)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_NivelDeEstudios)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelSeguirEstudiando)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAsesorar)
                    .addComponent(jButtonVolver))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonAsesorarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAsesorarActionPerformed
       try {
                int est = jComboBox1.getSelectedIndex();
                if (est == 0) {
                    engine.assertString("(respuesta 1)");
                    System.out.println("aui");
                } else if (est == 1) {
                    engine.assertString("(respuesta 2)");
                } else if (est == 2) {
                    engine.assertString("(respuesta 3)");
                } else if (est == 3) {
                    engine.assertString("(respuesta 4)");
                } else  {
                    engine.assertString("(respuesta 5)");
                }
                int curr = jComboBox4.getSelectedIndex();
                System.out.println(curr);
                if (curr == 0) {
                    engine.assertString("(curriculum y)");
                } else {
                    engine.assertString("(curriculum n)");
                }
                int niv = jComboBox2.getSelectedIndex();
                System.out.println(niv);
                if (niv == 0) {
                    engine.assertString("(nivel graduado)");
                } else if (niv == 1) {
                    engine.assertString("(nivel eso)");
                } else if (niv == 2) {
                    engine.assertString("(nivel bachiller)");
                } else {
                    engine.assertString("(nivel uni)");
                }
                int estu = jComboBox3.getSelectedIndex();
                System.out.println(estu);
                if (estu == 0) {
                    engine.assertString("(estudiar si)");
                } else {
                    engine.assertString("(estudiar no)");
                }
                int pensar = jComboBox5.getSelectedIndex();
                System.out.println(pensar);
                if (pensar == 0) {
                    engine.assertString("(pensar si)");
                } else {
                    engine.assertString("(pensar no)");
                }
                int metas = jComboBox6.getSelectedIndex();
                System.out.println(metas);
                if (metas == 0) {
                    engine.assertString("(metas y)");
                } else {
                    engine.assertString("(metas n)");
                }
                int feliz = jComboBox7.getSelectedIndex();
                System.out.println(feliz);
                if (feliz == 0) {
                    engine.assertString("(tiene felicidad)");
                } else {
                    engine.assertString("(tiene tristeza)");
                }
                int peso = jComboBox8.getSelectedIndex();
                System.out.println(peso);
                if (peso == 0) {
                    engine.assertString("(peso sobrepeso)");
                } else {
                    engine.assertString("(peso normal)");
                }
                int dieta = jComboBox9.getSelectedIndex();
                System.out.println(dieta);
                if (dieta == 0) {
                    engine.assertString("(dieta si)");
                } else {
                    engine.assertString("(dieta no)");
                }
                String deborah= "";
                //engine.batch("GUI/hola.clp");
                batch.batch("./GUI/hola.clp",engine);
                String linea = "";
            try {
                BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream("C://salida.txt")));
                try {
                    System.out.println(linea);
                    linea = reader2.readLine();
                    while(linea!=null){
                        deborah=(deborah+linea+"\n");
                        linea = reader2.readLine();
                    }
                } catch (IOException ex) {
                    Logger.getLogger(FramePreguntaAfectivoAyuda.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FramePreguntaAfectivoAyuda.class.getName()).log(Level.SEVERE, null, ex);
            }
                vector=new Vector();
                System.out.println(linea);
                JFrame  u= new Salida_Consejos(this.framePadre,deborah);
                this.setVisible(false);
            } catch (JessException ex) {
                Logger.getLogger(FramePreguntaAfectivoAyuda.class.getName()).log(Level.SEVERE, null, ex);
            }














}//GEN-LAST:event_jButtonAsesorarActionPerformed

private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed
    this.setVisible(false);
    this.framePadre.setVisible(true);
}//GEN-LAST:event_jButtonVolverActionPerformed

   
 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAsesorar;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JComboBox jComboBox7;
    private javax.swing.JComboBox jComboBox8;
    private javax.swing.JComboBox jComboBox9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabelAyuda;
    private javax.swing.JLabel jLabelSeguirEstudiando;
    private javax.swing.JLabel jLabel_NivelDeEstudios;
    private javax.swing.JLabel jLabel_que_Ayudamos;
    // End of variables declaration//GEN-END:variables

}
